<!DOCTYPE html>
<html>

<head lang="en">
  <meta charset="UTF-8">
  <title></title>
</head>

<body>
  <script>
    //new运算符
    var box1 = new RegExp('box'); //第一个参数字符串
    var box2 = new RegExp('box', 'ig'); //第二个参数可选模式修饰符
    //字面量创建
    var box3 = /box/; //直接用两个反斜杠
    var box4 = /box/ig; //在第二个斜杠后面加上模式修饰符

    console.log(box1);
    console.log(box2);
    console.log(box3);
    console.log(box4);


    //正则对象的创建方式一 通过字面量直接创建
    var reg1 = /[bcf]at/gi;

    //正则对象的创建方式二 通过RegExp构造函数来实例化正则对象
    var reg2 = new RegExp(/[bcf]at/,"gi");//常见形式
    var reg3 = new RegExp("[bcf]at","gi");

    console.log("a fAt bat ,a faT cat".match(reg1));//["fAt", "bat", "faT", "cat"]
    console.log("a fAt bat ,a faT cat".match(reg2));//["fAt", "bat", "faT", "cat"]
    console.log("a fAt bat ,a faT cat".match(reg3));//["fAt", "bat", "faT", "cat"]

  </script>
</body>

</html>